#include "fsm.h"
//#include <ncurses.h>

//char c;

state_type state = ST_STOP;
event_type event = EV_NONE;


int main()
{
    cls();

//    initscr();
//    int key = getch();
//    printf("%d", key);
//    endwin();

    while(1){
        char c;

//        printf("current state: %d\n", state);
//        printf("current event: %d\n", event);
        state = (*StateMachine[state][event])();

        //auto return from some state
        if(state == 2 || state == 3 || state == 5 || state == 6){
            event = EV_NONE;
        } else{
            //c=getchar();
            scanf(" %c", &c);
//            printf("char is %c\n", c);

            switch(c){
                case 'u':
                    event = EV_ENC_UP;
//                printf("ev_u\n");
                    break;
                case 'd':
//                printf("ev_d\n");
                    event = EV_ENC_DOWN;
                    break;
                case 'p':
//                printf("ev_p\n");
                    event = EV_ENC_PRESSED;
                    break;
                default:
//                printf("ev_n\n");
                    event = EV_NONE;
                    break;

            }
        }

    }

    return 0;
}
